/**
 * 
 */
package com.antilia.infomaresme.data.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.antilia.infomaresme.data.dao.interfaces.IImageInfosDao;
import com.antilia.infomaresme.data.dataobjects.ImageInfo;
import com.antilia.infomaresme.data.dataobjects.Item;

/**
 * @author Ernesto Reinaldo Barreiro
 *
 */
public class ImageInfosDao extends AbstractDaoHibernateImpl<ImageInfo> implements IImageInfosDao {

	/**
	 * @param domainClass
	 */
	public ImageInfosDao() {
		super(ImageInfo.class);
	}

	public List<ImageInfo> getImageInfos(Item item) {
		Criteria criteria = getSession().get().createCriteria(ImageInfo.class);
		criteria.add(Restrictions.eq("item", item));
		@SuppressWarnings("unchecked")
		List<ImageInfo> imageInfos = (List<ImageInfo>)criteria.list();
		return imageInfos;
	}

	public List<ImageInfo> getImageInfos(Item item, int start, int size) {
		Criteria criteria = getSession().get().createCriteria(ImageInfo.class);
		criteria.add(Restrictions.eq("item", item));
		criteria.setFetchSize(size);
		criteria.setFirstResult(start);
		@SuppressWarnings("unchecked")
		List<ImageInfo> imageInfos = (List<ImageInfo>)criteria.list();
		return imageInfos;
	}

	public Long countImageInfos(Item item) {
		if(item.getId() == null)
			return new Long(0);
		Criteria criteria = session.get().createCriteria(ImageInfo.class);
		criteria.setProjection(Projections.rowCount());
		criteria.add(Restrictions.eq("item", item));
		return (Long)(criteria.uniqueResult());
	}
	
	

}
